feat: allow removing property rules from validator by ids#171
Open
nieomylnieja wants to merge 6 commits into
Open
feat: allow removing property rules from validator by ids#171nieomylnieja wants to merge 6 commits into
nieomylnieja wants to merge 6 commits into
Conversation
- Updated `golangci-lint` from version 2.5.0 to 2.6.1 in `devbox.json` and `devbox.lock`. - Introduced a new `uuid` package for generating UUIDs. The `GenerateUUID` function creates UUIDs compliant with version 4 specifications. - Added comprehensive unit tests for the `uuid` package to ensure correctness, including format validation, uniqueness, length checks, and bit correctness. - Enhanced the `govy` package with new features: - Added `instanceID` for unique identification of `Validator` and `PropertyRules` instances. - Introduced `WithID` and `GetID` methods for `Validator` and `PropertyRules` to manage and retrieve identifiers. - Implemented `RemoveProperties` in `Validator` to allow selective removal of properties or nested validators. - Updated benchmarks in `rules` package to use `b.Loop()` for improved readability and consistency. - Added new examples and tests to demonstrate and validate the usage of `RemoveProperties` and `GetID` functionalities.
|
Test coverage changes:
|
This update introduces the ability to set custom identifiers for property rules using the `WithID` method. The feature is implemented across `PropertyRules`, `PropertyRulesForSlice`, and `PropertyRulesForMap`. These identifiers can be used for referencing specific rules, such as when removing properties from a validator. The changes include: - Implementation of the `WithID` method in `PropertyRules`, `PropertyRulesForSlice`, and `PropertyRulesForMap`. - Updates to the `GetID` method to prioritize user-supplied IDs over names and auto-generated UUIDs. - Modifications to example and test files to demonstrate and validate the new functionality. - Adjustments to the `Makefile` to ignore `node_modules` during markdown linting.
This update introduces a shift from name-based property removal to ID-based property removal in the `govy` package. The changes include: - Replacing `RemoveProperties` with `RemovePropertiesByID` in the `Validator` API. - Modifying `PropertyRules.GetID` and `Validator.GetID` to return only user-supplied IDs or auto-generated UUIDs, removing reliance on property names. - Updating examples and tests to reflect the new ID-based approach, ensuring clarity and consistency. - Simplifying the internal logic for ID retrieval by consolidating methods in the `instanceID` struct. These changes enhance the flexibility and reliability of property rule management, particularly in dynamic or complex validation scenarios.
nieomylnieja
added a commit
that referenced
this pull request
Nov 13, 2025
## Motivation Sometimes you want to create a modified validator without certain rules, the only way to achieve that currently is during the validator's definition. If you are importing a module which defines a validator, you have currently no way to change its rules in any way. That's why it would be useful to be able to remove properties' rules by name. ## Related Changes There's another PR which explores deleting properties by IDs: #171. ## Release Notes Added `govy.Validator.RemovePropertiesByName` method.
…ty-rules-by-id # Conflicts: # devbox.json # devbox.lock # pkg/govy/example_test.go # pkg/govy/rules.go # pkg/govy/rules_for_map.go # pkg/govy/rules_for_slice.go # pkg/govy/rules_test.go # pkg/govy/validation.go # pkg/govy/validator.go
Avoid mutating the enum value before bounds checking so unknown keys render their original numeric value and valid lookups use a safe zero-based index.
Ensure `ForPointer` and `Transform` create generated property IDs so `RemovePropertiesByID` can filter those rules consistently with `For`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Describe what is the motivation behind the proposed changes.
If possible reference the current solution/state of affairs.
Summary
Recap of changed code.
Related Changes
There's another PR which explores deleting properties by names: #172.
Testing
Each code change must be covered by unit tests.
Release Notes
If this change should be part of the Release Notes,
replace this entire paragraph with 1-3 sentences about the changes.
Otherwise, you MUST remove this section entirely.
Does this PR contain any breaking changes?
If so, add
## Breaking Changesheader and list the introduced changes there.